﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Diagnostics;

namespace SmartBlast
{
    class DataBase_DAO
    {

        private static String connectionString;
        private static DataBase_DAO _instance = null;

        public static DataBase_DAO getInstance()
        {
            if (_instance == null)
            {
                _instance = new DataBase_DAO();
            }
            return _instance;
        }

        private DataBase_DAO()
        {

        }

        public void makeConnection(string serverName)
        {
            connectionString = "Data Source=" + serverName + ";Initial Catalog=Smart_Blast;Integrated Security=SSPI;";
        }

        public DataTable executeSelectQuery(string cmdString)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = connection;
                cmd.CommandText = cmdString;
                SqlDataReader reader = cmd.ExecuteReader();
                DataTable data = new DataTable();
                data.Load(reader);
                return data;
            }
            
        }

        public void executeNonSelectQuery(string cmdString)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = connection;
                cmd.CommandText = cmdString;
                cmd.ExecuteNonQuery();
            }
        }
    }
}
